﻿using System;
using System.IO;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Jungle.Code.Core;
using Jungle.Code.DAL;
using System.Collections.Generic;
using Jungle.Code.Utils;
using Jungle.Code.BLL;
using System.Xml;

using Jungle.Articles.WebControls;
using Jungle.Articles;

    public partial class ArticleUser : BaseUserModule
	{
        private Language lang;
        private string[] langParams;
        SessionKeeper ts = new SessionKeeper();
        protected override void OnInit(EventArgs e)
        {
            LoadLanguage();
            hp_AllNews.Text = langParams[2];
            hp_AllNews.NavigateUrl = UrlHelper.GetSiteUrl() + "/" + lang.Name + "/articles.aspx";
            ts.SessionId = Session.SessionID.ToString();
            ts.GetData();

            LoadNew();
            base.OnInit(e);
        }
        // -------------------------------------------------------------------------------
        protected void LoadNew()
        {
            int NewId = 0;
            if (Request["i"] != null) NewId = Convert.ToInt32(Request["i"]);
            if (NewId != 0)
            {
                Article n = new Article();
                n.NewId = NewId;
                n.GetById();

                lb_Title.Text = n.PubDate.ToShortDateString() + "  " + n.Title;
                lb_Description.Text = n.Description;
            }
        }
        // -------------------------------------------------------------------------------
        private void LoadLanguage()
        {
            string ControlPath = "/Modules/Articles";
            int LangId = Node.GetByUrl(UrlHelper.GetRequestUrl().Substring(0, UrlHelper.GetRequestUrl().IndexOf(".aspx")).Replace("/main", "")).LangID;
            Language l = new Language(LangId, "", "", true, 0); l.GetById();
            lang = l;

            XmlDocument langDoc = new XmlDocument();
            langDoc.Load(Context.Server.MapPath(ControlPath + "/langs/" + l.Name + ".xml"));
            langParams = new string[langDoc.ChildNodes[1].ChildNodes.Count];
            for (int i = 0; i < langDoc.ChildNodes[1].ChildNodes.Count; i++)
            {
                langParams[i] = langDoc.ChildNodes[1].ChildNodes[i].InnerText;
            }
        }       
	}
